home *** CD-ROM | disk | FTP | other *** search
Perl Script | 1995-12-24 | 2.8 KB | 110 lines | [TEXT/R*ch] |
- #!/usr/bin/perl
-
- # Filter and concatenate HTML.pl
- # This script appends lines from one file to another, ignoring those lines that match a filter string
- # The output is an HTML document
- #
- # 12/24/95 Version 1.1.1
- # This script is free, public domain, no strings attached.
- # Igor Livshits <igorl@uiuc.edu>
-
-
- $openToAppend= ">> ";
- $macPathDelimiter= ":";
- $unixPathDelimiter= "/";
- $argumentCounter= 0;
- $newLineDelimiter= "\n";
-
- $omitFilterTag= "#-";
- $keepFilterTag= "#+";
- $true= (1 == 1);
- $false= (1 == 0);
- $htmlListItemLeader= "<LI> <A HREF= \"";
- $htmlListItemMiddle= "\">";
- $htmlListItemTrailer= "</A>" . $newLineDelimiter;
-
-
- # Read in the arguments passed to us from the AppleScript agent
- #
- $workingDirectory= $ARGV[$argumentCounter++] . $macPathDelimiter;
- $dataDirectory= $ARGV[$argumentCounter++] . $macPathDelimiter;
- $linesAddedFile= $ARGV[$argumentCounter++];
- $filtersFile= $ARGV[$argumentCounter++];
- $newFilesFile= $ARGV[$argumentCounter++];
- $urlFile= $ARGV[$argumentCounter++];
-
-
- # Read the URL
- #
- open(urlFile, $dataDirectory . $urlFile) || die "Cannot open $urlFile: $!";
- $rootURL= <urlFile>;
- if ($rootURL =~ /$newLineDelimiter$/) { chop ($rootURL); }
- close(urlFile);
-
-
- # Classify the filters
- #
- open(filtersFile, $dataDirectory . $filtersFile) || die "Cannot open $filtersFile: $!";
- $tagLine= <filtersFile>;
- if ($tagLine eq $keepFilterTag)
- {
- $omitMatches= $false; # filter matches are kept, the rest is dropped
- }
- else # default condition
- {
- $omitMatches= $true; # filter matches are dropped, the rest is kept
- if ($tagLine ne $omitFilterTag)
- {
- seek(filtersFile, 0, 0); # restart at the beginning of the file as the first line was not a tag
- }
- }
-
-
- # Read the filters
- #
- @filters= (); # clear the array
- while (<filtersFile>)
- {
- if (/$newLineDelimiter$/) { chop; }
- if ($_) { push(@filters, $_); } # only add non-blank filters
- }
- close(filtersFile);
-
-
- # Set up input and output files
- #
- open(linesAddedFile, $dataDirectory . $linesAddedFile) || die "Cannot open $linesAddedFile: $!";
- open(newFilesFile, $openToAppend . $workingDirectory . $newFilesFile) || die "Cannot open $newFilesFile: $!";
-
-
- # Filter and add valid lines
- #
- while(<linesAddedFile>)
- {
- if (/$newLineDelimiter$/) { chop; }
- $aLine= $_;
-
- $match= $false;
- foreach $filter (@filters)
- {
- if ($aLine =~ /$filter/)
- { # we have a match
- $match= $true;
- last;
- }
- }
- if ($omitMatches != $match)
- { # construct a list item using the path for the URL and the last leaf for the name
- @pathLeaves= split($unixPathDelimiter, $aLine);
- $aLinkName= pop (@pathLeaves);
- $aLink= $htmlListItemLeader . $rootURL . $aLine . $htmlListItemMiddle . $aLinkName . $htmlListItemTrailer;
- print (newFilesFile $aLink);
- }
- }
-
-
- # Clean up
- #
- close(linesAddedFile);
- close(newFilesFile);
-